<?php
/**
*
* @package ppkBB3cker
* @version $Id: memberlist_add1_fromthanks.php 1.000 2009-02-07 12:20:00 PPK $
* @copyright (c) 2008 PPK
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
*
*/

/**
* @ignore
*/
if (!defined('IN_PHPBB'))
{
	exit;
}

$sort_opt[$torrent_opt]=array('username', 'topic_title', 'downloaded', 'uploaded', 'completedat', 'ratio', 'startdat', 'to_go', 'last_action');
if(!in_array($opt_param, $sort_opt[$torrent_opt]))
{
	$opt_param=$sort_opt[$torrent_opt][0];
}

if($opt_param=='ratio')
{
	$sql_addon="s.uploaded/s.downloaded $opt_sort";
}
else if($opt_param=='tadded')
{
	$sql_addon="t.$opt_param $opt_sort";
}
else
{
	$sql_addon="$opt_param $opt_sort";
}

$sql="SELECT t.id thanks_id, u.username, u.user_id, u.user_colour, tt.topic_title, tt.topic_first_post_id, s.*, ttt.size FROM ".TRACKER_THANKS_TABLE." t LEFT JOIN ".USERS_TABLE." u ON t.to_user=u.user_id LEFT JOIN ".ATTACHMENTS_TABLE." a ON t.torrent_id=a.attach_id LEFT JOIN ".TOPICS_TABLE." tt ON a.post_msg_id=tt.topic_first_post_id LEFT JOIN ".TRACKER_SNATCHED_TABLE." s ON t.to_user=s.userid AND t.torrent_id=s.torrent LEFT JOIN ".TRACKER_TORRENTS_TABLE." ttt ON t.torrent_id=ttt.id WHERE t.user_id='$user_id' ORDER BY $sql_addon";
$result=$db->sql_query($sql);
while($userlist=$db->sql_fetchrow($result))
{
	$i3+=1;
	$assign_vars[$i3]['TORRENT_NAME'] = $userlist['topic_title'] ? "<a href='".append_sid("{$phpbb_root_path}viewtopic.$phpEx", "p={$userlist['topic_first_post_id']}")."#p{$userlist['topic_first_post_id']}'>{$userlist['topic_title']}</a>" : '&nbsp;';
	$assign_vars[$i3]['TORRENT_UP'] = get_formatted_filesize($userlist['uploaded']);
	$assign_vars[$i3]['TORRENT_USER'] = !empty($userlist['username']) ? get_username_string('full', $userlist['user_id'], $userlist['username'], $userlist['user_colour'], $userlist['username']) : '&nbsp;';
	$assign_vars[$i3]['TORRENT_DOWN'] = get_formatted_filesize($userlist['downloaded']);

	$assign_vars[$i3]['TORRENT_RATIO'] = get_ratio($userlist['uploaded'], $userlist['downloaded']);
	$assign_vars[$i3]['TORRENT_COMPLETED'] = @sprintf("%.2f%%", 100 * (1 - ($userlist["to_go"] / $userlist['size'])));
	$assign_vars[$i3]['TORRENT_START'] =  $userlist['startdat'] ? date('Y-m-d H:i:s', $userlist['startdat']) : '';
	$assign_vars[$i3]['TORRENT_END'] =  $userlist['completedat'] ? date('Y-m-d H:i:s', $userlist['completedat']) : '';
	$assign_vars[$i3]['TORRENT_LAST'] =  $userlist['last_action']? date('Y-m-d H:i:s', $userlist['last_action']) : '';
}
$db->sql_freeresult($result);
$assigned_vars=sizeof($assign_vars);
$opt_sort=$opt_sort=='DESC' ? 'ASC' : 'DESC';
foreach($sort_opt[$torrent_opt] as $v)
{
	$template->assign_vars(array(
		'TORRENT_SORT_HEADER_'.strtoupper($v) => $assigned_vars > 1 ? "$memberlist_url&amp;opt={$torrent_opt}&amp;opts={$opt_sort}&amp;optp={$v}#opt" : 'javascript:void(0);',
				)
			);
}
$torrent_info_curr=$torrent_opt;
$torrent_info[$torrent_opt]='<b>'.$torrent_info[$torrent_info_curr].'</b> ('.$i3.')';
$torrent_info_curr_explain[$torrent_opt]=$user->lang['USER_TORRENT_FROMTHANKS'];
?>
